#include <visitor_pattern.h>
#include <iostream>

void Keyboard::accept(ComputerPartVisitor *computerPartVisitor)
{
    computerPartVisitor->visit(this);
}

void Monitor::accept(ComputerPartVisitor *computerPartVisitor)
{
    computerPartVisitor->visit(this);
}

void Mouse::accept(ComputerPartVisitor *computerPartVisitor)
{
    computerPartVisitor->visit(this);
}

Computer::Computer()
{
    this->parts.push_back(new Mouse());
    this->parts.push_back(new Keyboard());
    this->parts.push_back(new Monitor());
}

Computer::~Computer()
{
    vector<ComputerPart*>::iterator it = this->parts.begin();
    for(; it != this->parts.end(); it++)
    {
        delete *it;
    }
}

void Computer::accept(ComputerPartVisitor *computerPartVisitor)
{
    vector<ComputerPart*>::iterator it = this->parts.begin();
    for(; it != this->parts.end(); it++)
    {
        (*it)->accept(computerPartVisitor);
    }
    computerPartVisitor->visit(this);
}

void ComputerPartDisplayVisitor::visit(Computer *computer)
{
    cout << "Displaying Computer." << endl;
}

void ComputerPartDisplayVisitor::visit(Mouse *mouse)
{
    cout << "Displaying Mouse." << endl;
}

void ComputerPartDisplayVisitor::visit(Keyboard *keyboard)
{
    cout << "Displaying Keyboard." << endl;
}

void ComputerPartDisplayVisitor::visit(Monitor *monitor)
{
    cout << "Displaying Monitor." << endl;
}
